package day12;

import java.util.Scanner;

//打印出杨辉三角形（要求打印出10行如下图）
//程序分析： 它的两个边都是1，内部其它都是肩上两个数的和
//       1
//      1 1
//     1 2 1
//    1 3 3 1
//   1 4 6 4 1
//1 5 10 10 5 1
public class Print {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.print("请输入层数：");
        int n=sc.nextInt();
        print(n);
    }
    public static void print(int n) {
        int[][] triangle = new int[n][];
        for (int i = 0; i < n; i++) {
            triangle[i] = new int[i + 1];
            triangle[i][0] = triangle[i][i] = 1;

            for (int j=1;j<i;j++) {
                triangle[i][j]=triangle[i-1][j-1]+triangle[i-1][j];
            }
        }
        for (int i=0;i<n;i++) {
            for (int s=0;s<n-i-1;s++) {
                System.out.print("  ");
            }

            for (int j=0;j<=i;j++) {
                System.out.printf("%4d", triangle[i][j]);
            }
            System.out.println();
        }
    }
}
